<%--
  Created by IntelliJ IDEA.
  User: Albert Lee
  Date: 2020/5/28
  Time: 18:51
  To change this template use File | Settings | File Templates.
--%>
<%--
  Created by IntelliJ IDEA.
  User: 长风
  Date: 2019/9/21
  Time: 20:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.sql.*" %>
<html>
<head>
    <title>数据更新</title>
</head>
<body>
<%!
    String DBDRIVER="com.mysql.cj.jdbc.Driver";
    String DBURL="jdbc:mysql://localhost:3306/student";
    String DBUSER="root";
    String DBPASS="123456";

%>
<%
    Connection conn=null;
    PreparedStatement pst=null;
    int rs=0;
    String id=null;
    String name=null;
    String age=null;
    String gender=null;
    String major=null;
%>
<%
    try{

        Class.forName(DBDRIVER);
        conn=DriverManager.getConnection(DBURL,DBUSER,DBPASS);
        request.setCharacterEncoding("utf-8");
        id=request.getParameter("id");
        name=request.getParameter("name");
        age=request.getParameter("age");
        gender=request.getParameter("gender");
        major=request.getParameter("major");
        String sql_update="update stu set name='"+name+"',age='"+age+"',gender='"+gender+"',major=' "+major+" 'where id='"+id+"'";
        pst=conn.prepareStatement(sql_update);
        rs=pst.executeUpdate();
        if(rs!=0){
            out.println("修改成功");
            %>
            <jsp:forward page="update.jsp"></jsp:forward><%--修改之后转到展示页面--%>
            <%
        }
    }
    catch(Exception e){
        out.println(e);
    }

%>
</body>
</html>



